package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.UserOper;
import com.ruoyi.system.domain.dto.AUserDto;
import com.ruoyi.system.domain.vo.UserOperVO;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AUser;
import com.ruoyi.system.service.IAUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小程序用户Controller
 *
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/system/aUser")
public class AUserController extends BaseController
{
    @Autowired
    private IAUserService aUserService;

    /**
     * 查询小程序用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AUser aUser)
    {
        startPage();
        List<AUser> list = aUserService.selectAUserList(aUser);
        return getDataTable(list);
    }


    /**
     * 查询小程序用户列表
     */
    @GetMapping("/UserOperList")
    public TableDataInfo UserOperList(UserOper userOper)
    {
        startPage();
        List<UserOperVO> list = aUserService.UserOperList(userOper);
        return getDataTable(list);
    }

    /**
     * 导出小程序用户列表
     */
    @Log(title = "小程序用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AUser aUser)
    {
        List<AUser> list = aUserService.selectAUserList(aUser);
        ExcelUtil<AUser> util = new ExcelUtil<AUser>(AUser.class);
        util.exportExcel(response, list, "小程序用户数据");
    }



    /**
     * 获取小程序用户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aUserService.selectAUserById(id));
    }

    /**
     * 新增小程序用户
     */
    @Log(title = "小程序用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AUser aUser)
    {
        return toAjax(aUserService.insertAUser(aUser));
    }

    /**
     * 修改小程序用户
     */
    @Log(title = "小程序用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AUser aUser)
    {
        return toAjax(aUserService.updateAUser(aUser));
    }

    /**
     * 调整小程序用户身份
     */
    @Log(title = "小程序用户", businessType = BusinessType.UPDATE)
    @PutMapping("/identity")
    public AjaxResult identity(@RequestBody AUserDto aUser) throws IOException, WxErrorException {
        return toAjax(aUserService.updateAUseridentity(aUser));
    }

    /**
     * 删除小程序用户
     */
    @Log(title = "小程序用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aUserService.deleteAUserByIds(ids));
    }

    @GetMapping("/allList")
    public AjaxResult allList()
    {
        return success(aUserService.selectAUserListAll());
    }
}
